<?php
namespace Admin\Controller;
use Tools\AdminController,    Model\Link_classModel;


class LinkclassController extends AdminController {
    function showlist(){
        $lcmd = new Link_classModel();
        
        $list = $lcmd -> order('link_class_sort asc') -> select();
        
        $this -> assign('list',$list);
        $this -> display();
    }
  
    
    function add(){
        $lcmd = new Link_classModel();
        if(!empty($_POST)){
            $shu = $lcmd -> create();
            if($shu){
                if($lcmd->add()){
                    $this->redirect('showlist');
                }else{
                    $this->redirect('showlist');
                }
            }else{
                $error = $lcmd->getError();
                $this->alert($error);
            }
        }
        
        $this -> display();
    }
    
    
    function delete($id){
        $lcmd = new Link_classModel();
        
        if($lcmd -> delete($id)){
            $this ->redirect('showlist');
        }else{
            $this ->redirect('showlist','',3,'删除失败');
        }       
    }
    
    
    function xiugai($id){
        $lcmd = new Link_classModel();    
        $list = $lcmd -> find($id);
        
        if(!empty($_POST)){
            $shu = $lcmd -> create();
            if($shu){
                if($lcmd->save()){
                    $this->redirect('showlist');
                }else{
                    $this->redirect('showlist');
                }
            }else{
                $error = $lcmd->getError();
                $this->alert($error);
            }
        }
        
        $this -> assign('list',$list);
        $this -> display();
    }
    
    
    function sort_change($id,$sort){
        $lcmd = new Link_classModel();

        $up['link_class_id']   = $id;
        $up['link_class_sort'] = $sort;
        
        $shu = $lcmd -> create($up);
        if($shu){
            $lcmd -> save($shu);
        }else{
            echo $lcmd -> getError();
        }
        
    }
    
}